package com.gjr.oss.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * @author 呙境仁
 * @create 2021-11-03 10:12
 * <p>
 * 读取配置文件内容
 */

// 当项目一启动，Spring接口，spring加载之后，执行接口一个方法
/* InitializingBean
     项目一启动实现 InitializingBean 该接口的类就会交给spring进行管理，在管理过程中会通过 @Value 注解将配置文件中的值都读取出来赋值给属性
* */


@Component
@PropertySource(value = "classpath:application.yaml")
@ConfigurationProperties(prefix = "aliyun.oss.file")
public class ConstantPropertiesUtils implements InitializingBean {
    @Value("${endpoint}")
    private String endpoint;
    @Value("${keyid}")
    private String keyId;
    @Value("${keysecret}")
    private String keySecret;
    @Value("${bucketname}")
    private String bucketName;

    // 定义公开静态常量
    public static String END_POINT;
    public static String ACCESS_KEY_ID;
    public static String ACCESS_KEY_SECRET;
    public static String BUCKET_NAME;

    @Override
    public void afterPropertiesSet() throws Exception {
        END_POINT = endpoint;
        ACCESS_KEY_ID = keyId;
        ACCESS_KEY_SECRET = keySecret;
        BUCKET_NAME = bucketName;
    }
}
